{extend name='index/base' /}

{block name='main'}
<body>
<div class="pd-20">
    {if condition="empty($agent)"}
    <form class="Huiform" id="loginform" action="{:url('agent/Editpwd/setPhone')}" method="post">
        <table class="table table-border table-bordered table-bg">
            <thead>
            <tr>
                <th colspan="2">添加手机号</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <th class="text-r" width="30%">手机号:</th>
                <td><input name="phonenumber" id="phonenumber" class="input-text" type="text" autocomplete="off" placeholder="手机号" tabindex="1" datatype="" nullmsg="请输入手机号！" errormsg="手机号">
                </td>
            </tr>
            <tr>
                <th class="text-r">请输入验证码：</th>
                <td>
                    <input style="width:70%; float:left;" name="code" id="newpassword2" class="input-text" type="password" autocomplete="off" placeholder="验证码" tabindex="3" datatype="*" recheck="newpassword" nullmsg="验证码！" errormsg="验证码！">

                    <input style="width:30%;" type="button" class="btn btn-success radius" id="resCode" value="免费获取验证码" onclick="send()">
                </td>
            </tr>
            <tr>
                <th></th>
                <td>
                    <button type="submit" class="btn btn-success radius" id="admin-password-save" name="admin-password-save"><i class="icon-ok"></i> 确定</button>
                </td>
            </tr>
            </tbody>

        </table>
    </form>
    {else \}
    <table class="table table-border table-bordered table-bg">
        <thead>
        <tr>
            <th colspan="2">手机号</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <th class="text-r" width="30%">手机号:</th>
            <td><input name="" id="" class="input-text" type="text"  value="{$agent.phonenumber}" disabled>
            </td>
        </tr>
        </tbody>
    </table>

    {/if}
</div>
<!--<script type="text/javascript">-->
    <!--$(".Huiform").Validform();-->
<!--</script>-->
<!--<script>-->
    <!--var _hmt = _hmt || [];-->
    <!--(function() {-->
        <!--var hm = document.createElement("script");-->
        <!--hm.src = "//hm.baidu.com/hm.js?080836300300be57b7f34f4b3e97d911";-->
        <!--var s = document.getElementsByTagName("script")[0];-->
        <!--s.parentNode.insertBefore(hm, s);-->
    <!--})();-->
    <!--var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");-->
    <!--document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F080836300300be57b7f34f4b3e97d911' type='text/javascript'%3E%3C/script%3E"));-->


<!--</script>-->
<script>
    var countdown=60;
    function send(){
        var obj = $("#resCode");
        var mobile = $("input[name='phonenumber']").val();
        if(mobile.match(/(^1[3|4|5|6|7|8|9]\d{9}$)|(^09\d{8}$)/) == null){
            alert('手机账号格式错误');
        }else{
            $.ajax({
                url : '/agent/editpwd/registersendMsg',
                type:"POST",
                data:{
                    mobile:mobile,
                },
                success:function(data){
                  if(data['msg']=='success'){
                      alert('验证码发送成功');
                      settime(obj);
                  }else{
                      alert(data['msg']);
                  }
                }
            });

        }




    }
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('disabled',false);
            obj.val("获取验证码");
            $("#resCode").css("background","#00bc12");
            countdown = 60;
            return;
        } else {
            obj.attr('disabled',true);
            obj.val("(" + countdown + ")S后重新发送");
            countdown--;
            $("#resCode").css("background","#ccc")
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }



</script>
</body>
</html>
{/block}
{block name='my'}